package com.zyl.pts.web.controller;

import com.zyl.pts.config.anno.SystemLog;
import com.zyl.pts.config.enums.CodeEnums;
import com.zyl.pts.config.result.Result;
import com.zyl.pts.domain.dto.IRDTO.IRConditionalDTO;
import com.zyl.pts.domain.dto.IRDTO.IRUpdateOrAddDTO;
import com.zyl.pts.service.IRService;
import com.zyl.pts.service.serviceImpl.IRServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version v1.0
 * @ProjectName: product_source
 * @Package: com.zyl.pts.web.controller
 * @ClassName: IRController
 * @Description TODO(指标记录模块)
 * @Author 翟玉龙
 * @Date 2024/11/19-16:51
 */
@Tag(name = "指标记录模块", description = "指标记录模块")
@RestController
@RequestMapping("/indexRecord")
@Validated
public class IRController {

    private final IRService irService;

    public IRController(IRServiceImpl irService) {
        this.irService = irService;
    }

    /**
     * 分页多条件查询指标记录信息接口
     * @param startWeight 开始重量
     * @param endWeight  结束重量
     * @param pageNum 页码
     * @param pageSize 每页数量
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "分页多条件查询指标记录信息接口")
    @Operation(summary = "分页多条件查询指标记录信息接口")
    @GetMapping("/query")
    public Result<?> queryIndexes(
            @RequestParam(value = "startWeight", required = false) Integer startWeight,
            @RequestParam(value = "endWeight", required = false) Integer endWeight,
            @RequestParam(value = "pageNum") @NotNull(message = "页码不能为空") int pageNum,
            @RequestParam(value = "pageSize") @NotNull(message = "页面大小不能为空") int pageSize
    ) {
        return Result.success(
                CodeEnums.SUCCESS,
                irService.queryIndexRecordByPage(new IRConditionalDTO(startWeight, endWeight, pageNum, pageSize))
        );
    }

    /**
     * 保存或更新指标记录接口
     * @param indexRecord 指标记录
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "保存或更新指标记录接口")
    @Operation(summary = "保存或更新指标记录接口")
    @PostMapping("/saveOrUpdate")
    public Result<?> saveOrUpdateIndexRecord(
            @RequestBody @Validated IRUpdateOrAddDTO indexRecord
    ) {
        return Result.success(
                irService.addOrUpdateIndexRecord(indexRecord)
        );
    }

    /**
     * 根据id删除指标记录
     * @param ird_id 指标记录id
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "根据id删除指标记录")
    @Operation(summary = "根据id删除指标记录")
    @DeleteMapping("/deleteById/{ird_id}")
    public Result<?> deleteIndexRecordById(
            @PathVariable("ird_id") Integer ird_id
    ) {
        return Result.success(
                irService.deleteIndexRecordById(ird_id)
        );
    }

    /**
     * 批量删除指标记录
     * @param ids 指标记录id集合
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "批量删除指标记录")
    @Operation(summary = "批量删除指标记录")
    @DeleteMapping("/deleteByIdAll")
    public Result<?> deleteIndexRecordByIds(
            @RequestBody List<Integer> ids
    ) {
        return Result.success(
                irService.deleteIndexRecordByIds(ids)
        );
    }
}
